package Queue;


import Array.Array;

public class ArrayQueue<E> implements Queue<E> {


    private Array<E> array;

    public ArrayQueue(int capacity) {
        //会浪费一个位置的空间
        this.array = new Array(capacity + 1 );
    }

    public ArrayQueue() {
        this.array = new Array();
    }

    public int getSize() {
        return array.getSize();
    }

    public void enqueue(E e) {
        array.addLast(e);
    }

    public E dequeue() {
        return array.removeFirst();
    }

    public E getFront() {
        return array.getFirst();
    }

    public boolean isEmpty() {
        return false;
    }

    public int getCapacity() {
        return 0;
    }


    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(String.format("Queue : "));
        builder.append(" front [ ");
        for (int i = 0; i < array.getSize(); i++) {
            builder.append(array.get(i));
            if (i != array.getSize() - 1) {
                builder.append(",");
            }
        }
        builder.append(" ] tail ");
        return builder.toString();
    }
}
